package web.servlet;

import domain.Account;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import persistence.impl.AccountDAOImpl;

import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(name = "usernameIsExist", urlPatterns = "/usernameIsExist")
public class UsernameExistServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String username = req.getParameter("username");
        AccountDAOImpl accountDAO = new AccountDAOImpl();
        Account account = accountDAO.getAccountByUsername(username);

        resp.setContentType("text/plain");
        PrintWriter out = resp.getWriter();

        if(account == null)
        {
            out.print("Not Exist");
        }
        else
        {
            out.print("Exist");
        }
    }
}
